<template>
	<view style="padding-top: 170rpx;background-color: #f8f8f8;">
		<u-navbar :title="title" @rightClick="rightClick" :autoBack="true">
		</u-navbar>

		<!-- 失物招领 -->
		<u-sticky offset-top="90" v-if="params.type==='3'">
			<view style="background-color: #ffffff;padding-top: 20rpx;" v-if="params.type==='3'">
				<view style="margin-left: 28rpx;margin-right: 28rpx;">
					<u-search :showAction="false" :animation="false" v-model="params.content"
						@search="getList()"></u-search>
				</view>
				<view style="display: flex;justify-content: center;">
					<u-tabs :list="list1" @click="click"></u-tabs>
				</view>
			</view>
		</u-sticky>
		<list :loveList="loveList" :type="params.type" :shiwuType="shiwuType"></list>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import list from '../components/list.vue'
	export default {
		data() {
			return {
				user: '',
				timer: null,
				timer2: null,
				total: 0,
				shiwuType: 0,
				title: '',
				loveList: [],
				list1: [{
					name: '失物招领',
				}, {
					name: '寻物启事',
				}],
				params: {
					loginId: 0,
					pageSize: 6,
					pageNum: 1,
					// top: 1,
					zanId: '',
					type: 1,
					zhaolingType: '',
					content: '',
					userId: ''
				},
			}
		},
		onUnload() {
			console.log(123)
			if (this.timer2) {
				clearTimeout(this.timer2); // 清除定时器  
			}
		},
		onLoad(option) {
			if (option.type !== '' && option.type !== null && option.type !== undefined) {
				this.params.type = option.type
				this.title = option.title
			}
			this.getList()
		},
		onPullDownRefresh() {
			uni.showLoading({
				title: '加载中'
			});
			this.params.pageNum = 1
			this.getList()
			this.timer = setTimeout(() => {
				uni.stopPullDownRefresh()
				uni.hideLoading();
			}, 1000)
		},
		onReachBottom() {
			this.getBottom()
		},
		methods: {
			click(item) {
				this.params.zhaolingType = item.index
				this.shiwuType = item.index
				this.getList()
			},
			async getBottom() {
				const that = this
				if (this.loveList.length < this.total) {
					this.params.pageNum++
					uni.showLoading({
						title: '加载中'
					});
					uni.request({
						url: that.$baseurl + "/font/list",
						method: 'GET',
						data: that.params,
						success(res) {
							that.loveList = [...that.loveList, ...res.data.rows]
						}
					})
					uni.hideLoading();
				} else {
					this.$refs.uToast.show({
						type: 'default',
						title: '默认主题',
						message: "到底了...",
						iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/default.png'
					})
				}
			},
			async getList() {
				this.user = uni.getStorageSync("loginUser")
				if (this.user !== '' && this.user !== null && this.user !== undefined) {
					this.params.loginId = this.user.id
				}
				if (this.params.type === '3') {
					if (this.params.zhaolingType === '' || this.params.zhaolingType === null) {
						this.params.zhaolingType = 0
					}
				} else {
					this.params.content = ''
					this.params.zhaolingType = ''
				}
				const res = await this.$myRuquest({
					url: '/font/list',
					data: this.params
				})
				this.loveList = res.data.rows
				this.total = res.data.total
			},
			rightClick() {
				uni.navigateBack()
				console.log('rightClick');
			},
			leftClick() {
				uni.navigateBack()
				console.log('leftClick');
			},
			async getBottom() {
				const that = this
				if (this.loveList.length < this.total) {
					this.params.pageNum++
					uni.showLoading({
						title: '加载中'
					});
					uni.request({
						url: that.$baseurl + "/font/list",
						method: 'GET',
						data: that.params,
						success(res) {
							that.loveList = [...that.loveList, ...res.data.rows]
						}
					})
					uni.hideLoading();
				} else {
					this.$refs.uToast.show({
						type: 'default',
						title: '默认主题',
						message: "到底了...",
						iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/default.png'
					})
				}
			},
		},
		onPullDownRefresh() {
			uni.showLoading({
				title: '加载中'
			});
			this.params.pageNum = 1
			this.getList()
			this.timer = setTimeout(() => {
				uni.stopPullDownRefresh()
				uni.hideLoading();
			}, 1000)
		},
		onReachBottom() {
			this.getBottom()
		},
		onUnload() {
			console.log(123)
			if (this.timer2) {
				clearTimeout(this.timer2); // 清除定时器  
			}
		},
		components: {
			"list": list,
		},
	}
</script>

<style>

</style>